package com.heima.bos.web.action.impl;

import java.util.List;

import javax.annotation.Resource;

import org.apache.struts2.ServletActionContext;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.heima.bos.domain.Workordermanage;
import com.heima.bos.service.BaseService;
import com.heima.bos.service.WorkordermanageService;
import com.heima.bos.web.action.WorkordermanageActionInter;
import com.opensymphony.xwork2.ActionContext;
@Controller
@Scope("prototype")
public class WorkordermanageAction extends BaseAction<Workordermanage> implements WorkordermanageActionInter{
	@Resource
	private WorkordermanageService workordermanageService;
	/**
	 * 启动工作单
	 */
	public String start(){
		workordermanageService.start(entity.getId());
		return list();
	}
	
	/**
	 * 查询当前未启动的工作单
	 */
	public String list(){
		List<Workordermanage> list = workordermanageService.findNoStartList();
		ActionContext.getContext().getValueStack().set("list", list);
		return "noStartList";
	}
	/**
	 * 为快速录入工作单提供数据
	 */
	public String pageQuery(){
		
		List<Workordermanage> list = workordermanageService.findAll();
		String[] excludes = new String[]{"prodtimelimit","prodtype","sendername","senderphone",
										 "senderaddr","receivername","receiverphone","receiveraddr",
										 "feeitemnum","actlweit","vol","managerCheck","updatetime"};
		
		writeList2Json(list, excludes);
		return NONE;
	}
	/**
	 * 更新工作单
	 */
	public String update(){
		String flag = "1";
		try{
			Workordermanage order = workordermanageService.findById(entity.getId());
			if(order == null){
				workordermanageService.save(entity);
			}else{
				order.setArrivecity(entity.getArrivecity());
				order.setProduct(entity.getProduct());
				order.setNum(entity.getNum());
				order.setWeight(entity.getWeight());
				order.setFloadreqr(entity.getFloadreqr());
				workordermanageService.update(order);
			}
			ServletActionContext.getResponse().getWriter().print(flag);
		}catch(Exception e){
			flag = "2";
		}
//		return "updateSuccess";
		return NONE;
	}
	@Override
	protected BaseService<Workordermanage> getService() {
		return workordermanageService;
	}
}
